package bootstrap.liftweb

import _root_.net.liftweb._
import com.sun.xml.internal.bind.util.Which
import common._
import util._
import http._
import sitemap._
import sitemap.Loc._
import Helpers._

/**
  * A class that's instantiated early and run.  It allows the application
  * to modify lift's environment
  */
class Boot {
  def boot {
    // where to search snippet
    LiftRules.addToPackages("com.jeff.mavenlift")

    // Build SiteMap
    val entries = Menu(Loc("Home", List("index"), "Home")) :: Nil
    LiftRules.setSiteMap(SiteMap(entries:_*))

    def displaySometimes_? : Boolean =
    (millis / 1000L / 60L) % 2 == 0

//    def sitemap(): SiteMap = SiteMap(
//      Menu.i("home") / "index",
//      Menu.i("someTimes") / "someTimes" >> If(displaySometimes_? _, S ? "Can't view now"),
//
//      //a menu with submenus
//      Menu.i("Info") / "Info" submenus (
//        Menu.i("About") / "about" >> Hidden >> LocGroup("bottom"),
//        Menu.i("Contact") / "contact",
//        Menu.i("Feedback") / "feedback" >> LocGroup("bottom")
//      ),
//
//      Menu.i("Sitemap") / "sitemap" >> Hidden >> LocGroup("bottom"),
//      Menu.i("Dynamic") / "dynamic", //a page with dynamic content
//
////      Param.menu,
//
////      Menu.param[Which](
////        "Recurse",
////        "Recurse",
////        {case "one" => Full(First())
////         case "two" => Full(Second())
////         case "both" => Full(Both())
////         case _ => Empty},
////        w => w.toString
////      ) / "recurse",
//
//      // more complex because this menu allows anything in the
//      // /static path to be visible
//      Menu.i("Static") / "static" / **
//    )
//
//    // set the sitemap.  Note if you don't want access control for
//    // each page, just comment this line out.
//    LiftRules.setSiteMapFunc(() => sitemap())

    LiftRules.ajaxStart = Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)
    LiftRules.ajaxEnd = Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)

//    LiftRules.early.append(_.setCharacterEncoding("UTF-8"))

    LiftRules.htmlProperties.default.set((r: Req) => new Html5Properties(r.userAgent))
    
  }
}

